//
//  StatisticsServer.hpp
//  Simulation
//
//  Created by Christopher Kemsley on 3/7/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef Simulation_StatisticsServer_hpp
#define Simulation_StatisticsServer_hpp

#define	StatsNamespaceBegin	namespace Statistics {
#define	StatsNamespaceEnd	}

#include <string>
#include <map>
#include <ostream>
#include <fstream>
#include "Types.hpp"
#include "URL.hpp"

StatsNamespaceBegin





class	Server ;
struct	Node ;





class	Server
{
public:
	
	static void	loadConfiguration	( Sim::URL url ) ;
	
	
private:
	
	static Server&	shared () ;
	
	Server () ;
	~Server () ;
	std::ofstream	mStream ;
	std::string		mName ;
	
	friend class Node ;
	
	void logNode	( Node const & node ) ;
	
	friend std::ostream&	operator<<	( std::ostream & stream , Node const & node ) ;
} ;





struct	Node
{
	Node	( std::string const & name ) ;
	~Node	() ;
	
	enum {
		kIdle			=	0 << 0 ,
		kBusy			=	1 << 0 ,
		kErronious		=	3 << 0 ,
		kRetroactive	=	1 << 2
	} ;
	typedef unsigned char Region ;
	
	static std::string const	regionTitle ( Region const & region ) ;
	
	
	void	operator<<	( Region const & region ) ;
	
	
private:
	typedef std::map<Region,Sim::Interval>	Map ;
	std::string const	mName ;
	Region				mRegion ;
	Sim::Interval		mTime ;
	Map					mPeriods ;
	
	friend std::ostream&	operator<<	( std::ostream & stream , Node const & node ) ;
} ;





StatsNamespaceEnd

#endif
